<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	String otype = (String)request.getAttribute("otype");       //接受type
	String type = (String)request.getAttribute("type");       //接受type
	String newsId = (String)request.getAttribute("newsId");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>新增新闻</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript" src="<%=basePath%>ckeditor/ckeditor.js"></script>
	<script type="text/javascript">
	
		var otype = "<%=otype%>";  							
		var type = "<%=type%>";   							//接受信息类型  1新闻2公告3新手上路
		var newsId = "<%=newsId%>";
		
		//保存信息,添加和编辑都可以操作
		function save(){
			$('#saveBtn').attr('disabled','disabled');
			var title = escape(escape($('#title').val()));               //获取title值
			var content = escape(escape(CKEDITOR.instances.content.getData()));          //获取content值
			var author = escape(escape($('#author').val()));             //获取author值
			var time = $("#time").datebox("getValue");                   //获取time值
			var layerOrder = escape(escape($('#layerOrder').val()));     //获取layerOrder值
			
			
			if($('#fm').form('validate')){
				var url = "";
				if(otype=="add"){
					url = path +"/news/save.do?type="+type+"&title="+title+"&content="+content+"&layerOrder="+layerOrder+"&author="+author+"&time="+time;
				}else{  //update
					url = path +"/news/update.do?newsId="+newsId+"&title="+title+"&content="+content+"&author="+author+"&time="+time+"&layerOrder="+layerOrder+"&type="+type;
				}
					//执行ajax操作
				$.ajax({
					  url:url,
					  success: function(data) {
						  if(data == "1"){
							  window.location = path+"/news/newsMgr.do?type="+type;
						   }else{
							   alertBox("操作失败！");
						   } 
					  }
				});
			}
		}
		
		//撤销回退
		function callback(){
			window.location = path+"/news/newsMgr.do?type="+type;
		}
		
	</script>
  </head>
  
  <body>
   <div class="right">
	<h1>
		<c:if test="${type=='1'}"><!-- 表示是新闻 -->
			<b>${otype=='add'?'新增新闻':'编辑新闻' }</b>
		</c:if>
		<c:if test="${type=='2'}"><!-- 表示是公告 -->
			<b>${otype=='add'?'新增公告':'编辑公告' }</b>
		</c:if>
		<c:if test="${type=='3'}"><!-- 表示是公告 -->
			<b>${otype=='add'?'新增新手指导':'编辑新手指导' }</b>
		</c:if>
	<span>
		<img src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" />
	</span></h1>
	<div class="ri_main">
	<form id="form">
		<table width="100%" border="0" cellspacing="1" cellpadding="8" style="background:#d9d9d9;">
		  <tr>
		    <td width="15%" align="right" bgcolor="#FFFFFF">标题</td>
		    <td bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
		      <input id="title" name="title" class="easyui-validatebox" required="true" style="width:400px;" value="${news != null?news.title:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td width="15%" align="right" bgcolor="#FFFFFF">内容</td>
		    <td bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
		      <textarea rows="40" cols="80" class="ckeditor" name="content" id="content">
		      	${news != null?news.content:'' }
			  </textarea>
		    </td>
		  </tr>
		  <tr>
		    <td width="15%" align="right" bgcolor="#FFFFFF">作者</td>
		    <td bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
				<input id="author" name="author" class="easyui-validatebox" required="true" style="width:200px;" value="${news != null?news.author:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td width="15%" align="right" bgcolor="#FFFFFF">发布时间</td>
		    <td bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
				<input id="time" name="time" class="easyui-datetimebox" required="true" style="width:200px;" value="${news != null?news.time:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td width="15%" align="right" bgcolor="#FFFFFF">排序方式</td>
		    <td bgcolor="#FFFFFF" align="left"><label for="textfield"></label>
				<input id="layerOrder" name="layerOrder" class="easyui-validatebox" style="width:200px;" value="${news != null?news.layerOrder:'' }" />
		    </td>
		  </tr>
		  <tr>
		    <td bgcolor="#FFFFFF" colspan="4" align="center">
		    	<a href="javascript:void(0);" id="saveBtn" class="easyui-linkbutton" iconCls="icon-ok" onclick="save()">保存</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-cancel" onclick="callback()">取消</a>
		    </td>
		  </tr>
		</table>
	</form>
	</div>
	</div>
  </body>
</html>
